<?php


namespace app\crontab\controller\once;


use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 补救房源SourceUrl
 * Class RemedySourceUrl
 * @package app\crontab\controller
 */
class RemedySourceUrl extends Command {

    protected function configure() {
        $this->setName('RemedySourceUrl');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        //找到房源对应的拍卖纪录的 source_url
        $house = db("house")
            ->alias('h')
            ->leftJoin('house_auction ha', 'ha.id=h.auction_id')
            ->field('ha.source_url,h.id')
            ->order('id asc')
            ->select();
        $arr = [];
        foreach ($house as $k => $v) {
            if (!empty($v['source_url'])) {
                if (!in_array(db("house")->where('id', $v['id'])->update(['source_url' => $v['source_url']]), [0, 1])) {
                    $arr[] = $v['id'];
                }
            }
        }
        echo "end\n";
        print_r($arr);
        die;
    }

}
